package com.udl.emailfs.mail;

import java.io.IOException;
import java.util.Comparator;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.mail.Message;
import javax.mail.MessagingException;

public class MailComparator implements Comparator<Message> {

    public int compare(Message messA, Message messB) {
        int comp=0;
        try {
            String subjA = Mail.getSubject(messA);
            long timeA = Long.parseLong(subjA.substring(71, 84));
            String subjB = Mail.getSubject(messB);
            long timeB = Long.parseLong(subjB.substring(71, 84));
            comp = (int) (timeA - timeB);
        } catch (MessagingException ex) {
            Logger.getLogger(MailComparator.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(MailComparator.class.getName()).log(Level.SEVERE, null, ex);
        }
        return comp;
    }
}
